package com.zrgj.manager.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.zrgj.domain.User;
import com.zrgj.domain.UserComments;
import com.zrgj.manager.mapper.ProductMapper;
import com.zrgj.manager.mapper.UserCommentsMapper;
import com.zrgj.manager.mapper.UserMapper;
import com.zrgj.manager.service.IUserCommentsService;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Service
@Component
public class UserCommentsServiceImpl implements IUserCommentsService {
    private UserCommentsMapper userCommentsMapper;
    private UserMapper userMapper;

    public UserCommentsServiceImpl(UserCommentsMapper userCommentsMapper, UserMapper userMapper) {
        this.userCommentsMapper = userCommentsMapper;
        this.userMapper = userMapper;
    }

    @Override
    public List<UserComments> selectByPid(Integer productId) {
        List<UserComments> userComments = userCommentsMapper.selectByPid(productId);
        List<UserComments> commentsList = new ArrayList<>();

        for (UserComments comments: userComments){
            User user = userMapper.selectById(comments.getUserId());
            comments.setUser(user);
            commentsList.add(comments);
        }
        return commentsList;
    }

    @Override
    public void insert(UserComments userComments) {
        userCommentsMapper.insert(userComments);
    }


}
